﻿using System.ComponentModel.DataAnnotations;

namespace FlyingHat.Model.Models
{
    public class ClassificationTreeModel
    {

        public long Id { get; set; }

        public string Title { get; set; } = string.Empty;
        public string Code { get; set; } = string.Empty;
        public string Name { get; set; } = string.Empty;
        public string ParentName { get; set; } = string.Empty;

        public long ParentId { get; set; }
        public long SpreadId { get; set; }
        public int Sort { get; set; }

        public bool Spread => Children != null && Children.Any(i => i.ParentId == SpreadId || i.Spread);

        public bool Last => Children == null || !Children.Any();

        public List<ClassificationTreeModel> Children { get; set; } = new List<ClassificationTreeModel>();
        public ClassificationModel BasicData
        {
            get
            {
                return new ClassificationModel { Id = Id, Code = Code, Name = Name, ParentId = ParentId, Sort = Sort, ParentName = ParentName };
            }
        }
    }
    public class ClassificationModel
    {

        public long Id { get; set; }
        [Required(ErrorMessage = "分类号必须填写")]
        public string Code { get; set; } = string.Empty;
        [Required(ErrorMessage = "分类名称必须填写")]
        public string Name { get; set; } = string.Empty;

        public long ParentId { get; set; }
        public string ParentName { get; set; } = string.Empty;

        public int Sort { get; set; }


    }
}
